/* 
 * File:   outil.cpp
 * Author: landry
 * 
 * Created on 10 octobre 2009, 09:06
 */
#include "outil.h"
//#include "externalVariable.h"

/*#include "client.h"
include <iostream>
#include <fstream>
#include <string.h>
#include "simulation.h"*/


//extern vector<Client> clients;

Outil::Outil() {
}

Outil::Outil(const Outil& orig) {
}

Outil::Outil(char* file_name) {
    this->file_name = file_name;

    int num;
    int tempsArrivee;
    int tempsService;
    list<string> L;
    fstream fichier(file_name,ios::in | ios::out );
       Client *objClient;
        int i=0;
        Client **listeDesClients;
        if(fichier){
            if(!fichier.fail()){
                string ligne;
                while(getline(fichier, ligne)){
                    vector<string> tokens;
                    //cout << ligne << endl;
                    this->tokenize(ligne,tokens,"\t");

                    num = this->conversion(tokens.at(0));
                    tempsArrivee = this->conversion(tokens.at(1));
                    tempsService = this->conversion(tokens.at(2));
                    CLIENTS clt;
                    clt.num_cli = this->conversion(tokens.at(0));
                    clt.tpsarrivee = this->conversion(tokens.at(1));
                    clt.tpsservice = this->conversion(tokens.at(2));
                    //Client clt();
                    //cl.push_back(clt);
                    L.push_back(ligne);
                    clients.push_back(clt);
                }
            }
            else{
                cout << "Impossible de lire le fichier !" << endl;
            }
        }
        else{
            cerr << "Erreur à l'ouverture : Impossible de trouver le fichier!" << endl;
	    exit(-1);
        }
        
       // cout << clients.size() << endl;

        

        list<CLIENTS>::iterator t;




}


void Outil::tokenize(const string& str,vector<string>& tokens,string delimiters)
    {
        //string delimiters ="\t";
        // Skip delimiters at beginning.
        string::size_type lastPos = str.find_first_not_of(delimiters, 0);
        // Find first "non-delimiter".
        string::size_type pos     = str.find_first_of(delimiters, lastPos);

       while (string::npos != pos || string::npos != lastPos)
       {
           // Found a token, add it to the vector.
           tokens.push_back(str.substr(lastPos, pos - lastPos));
           // Skip delimiters.  Note the "not_of"
           lastPos = str.find_first_not_of(delimiters, pos);
           // Find next "non-delimiter"
           pos = str.find_first_of(delimiters, lastPos);
       }
  }


int Outil::conversion(string st){
    istringstream iss(st);

    int tmp;
    iss>>tmp; //on introduit a dans tmp ki est un type int
                 //maintenant, tmp contient le string convertit en entier
    return tmp;
}




   

Outil::~Outil() {
}

